{% extends "frame/tabpages.html" %}
{% block content %}
<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">{% csrf_token %}
                <div class="layui-form-item">
                    <label for="id_name" class="layui-form-label">
                        <span class="x-red">*</span>分类名称</label>
                    <div class="layui-input-inline">
                        <input type="text" id="id_name" name="name" required="" lay-verify="required" autocomplete="off" class="layui-input" value="{{category.name}}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <button class="layui-btn" lay-filter="update" lay-submit="">修改</button>
                </div>
            </form>
        </div>
    </div>
</body>
{% endblock %}

{% block jsscript %}
<script>
layui.use(['form', 'layer','jquery'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
        layer = layui.layer;

        //监听提交
        form.on('submit(update)',
        function(data) {
            //发异步，把数据提交给php
            $.ajax({
                type:'post',
                url:"{% url 'product:show_categoryUpdate' 00 %}".replace('0', {{category.id}}),
                data:data.field,
                success:function(res){
                        layer.msg("更新成功!");
                        xadmin.close();//关闭当前frame
                        xadmin.father_reload();// 可以对父窗口进行刷新 
                },
                error:function(res)
                {
                    layer.msg("更新失败!");
                }
            });
            return false;
        });
    }
);
</script>
{% endblock %}
